package com.example.myapplication2030606131;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView textView;
    private RadioButton carYinqing;
    private RadioButton carBoli;
    private RadioButton carFanxiangpan;
    private Button brnGoumai;
    private TextView textGouwuche;
    private TextView textLiebiao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        carYinqing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    textLiebiao.setText("选中：" +buttonView.getText().toString());
                }else {
                    textLiebiao.setText("取消选中" +buttonView.getText().toString());
                }
            }
        });
        carBoli.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    textLiebiao.setText("选中：" +buttonView.getText().toString());
                }else {
                    textLiebiao.setText("取消选中" +buttonView.getText().toString());
                }
            }
        });
        carFanxiangpan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    textLiebiao.setText("选中：" +buttonView.getText().toString());
                }else {
                    textLiebiao.setText("取消选中" +buttonView.getText().toString());
                }
            }
        });
        brnGoumai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                   String msg="选中：";
                   if(carYinqing.isChecked()){
                       msg+="\n"+carYinqing.getText().toString();
                   }
                if(carBoli.isChecked()){
                    msg+="\n"+carBoli.getText().toString();
                }
                if(carFanxiangpan.isChecked()){
                    msg+="\n"+carFanxiangpan.getText().toString();
                }
                   textLiebiao.setText(msg);
            }
        });
    }

    private void initView() {
        textView = (TextView) findViewById(R.id.textView);
        carYinqing = (RadioButton) findViewById(R.id.car_yinqing);
        carBoli = (RadioButton) findViewById(R.id.car_boli);
        carFanxiangpan = (RadioButton) findViewById(R.id.car_fanxiangpan);
        brnGoumai = (Button) findViewById(R.id.brn_goumai);
        textGouwuche = (TextView) findViewById(R.id.text_gouwuche);
        textLiebiao = (TextView) findViewById(R.id.text_liebiao);
    }
}